home *** CD-ROM | disk | FTP | other *** search
/ Essentials of Interactive Physiology / Essentials of Interactive Physiology.iso / pc / files / code / utilities.js < prev   
Encoding:
Text File  |  2000-10-13  |  2.0 KB  |  64 lines

  1. // return the param passed in from the URL after the ? (i.e. - "http://buildframes.html?respiratory/conresp")
  2. // would return "respiratory/conresp"
  3. function getParamFromURL() {
  4.     vsURL = new String(document.location);
  5.     
  6.     vsParam = vsURL.substring(vsURL.indexOf("?") + 1, vsURL.length);
  7.     
  8.     return vsParam;
  9. }
  10.  
  11. // return the number of items in a string delimited by xsDelimiter
  12. // returns 1 if no delimiters so "" returns 1 whereas "," returns 2
  13. function getNumberOfItemsFromDelimitedString(xsStringToSplit, xsDelimiter) {
  14.    vsSplitArray = xsStringToSplit.split(xsDelimiter);
  15.    
  16.    return vsSplitArray.length;
  17. }
  18.  
  19. // return the nth item from a string delimited by xsDelimiter
  20. function getNthItemFromDelimitedString(xsStringToSplit, xiWhich, xsDelimiter) {
  21.    vsSplitArray = xsStringToSplit.split(xsDelimiter);
  22.    
  23.    return vsSplitArray[xiWhich - 1];
  24. }
  25.  
  26. // return the nth item from a string delimited by xsDelimiter
  27. function getLastItemFromDelimitedString(xsString, xsDelimiter) {
  28.    vsSplitArray = xsString.split(xsDelimiter);
  29.    vsItemToReturn = getNthItemFromDelimitedString(xsString, vsSplitArray.length, xsDelimiter);
  30.    
  31.    return vsItemToReturn;
  32. }
  33.  
  34. // strip the nth item from a string delimited by xsDelimiter (and the last delimiter)
  35. function stripLastItemFromDelimitedString(xsStringToStrip, xsDelimiter) {
  36.      // get the location of the last comma (the char before the param)
  37.      viLastDelimLoc = xsStringToStrip.lastIndexOf(xsDelimiter);
  38.      
  39.      if(viLastDelimLoc != -1)
  40.          vsToReturn = xsStringToStrip.substring(0, viLastDelimLoc);
  41.     else
  42.         vsToReturn = xsStringToStrip;
  43.     
  44.     return vsToReturn;
  45. }
  46.  
  47.  
  48. // pad a number (as a string) with leading 0's
  49. function padNumToXDigits(xsNumAsString, xiNumDigits) {
  50.     vsCurrentStringLen = xsNumAsString.length;
  51.     for(i=vsCurrentStringLen; i<xiNumDigits; i++) {
  52.         xsNumAsString = "0" + xsNumAsString;
  53.     }
  54.     
  55.     return xsNumAsString;
  56. }
  57.  
  58. // change the image xsImageName to the xsImageSrc
  59. function swapImages(xsImageName, xsImageSrc) {
  60.     if (document.images) {
  61.             document.images[xsImageName].src = xsImageSrc;
  62.     }
  63. }
  64.